package com.accp.demo.service.sale;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.accp.demo.mapper.sale.ISaleOrderMapper;
import com.accp.demo.pojo.PageBean;
import com.accp.demo.pojo.sale.SaleOrder;
import com.accp.demo.pojo.sale.SaleOrderDetail;
import com.accp.demo.util.TestUtil;


@Service
public class SaleOrderservice {
	@Autowired
private ISaleOrderMapper iSaleOrderMapper;
/**
 * 分页主祥查询
 */
public List<SaleOrder> queryPagesaleOrder(Integer pageNum,Integer pageSize){
	return iSaleOrderMapper.queryPagesaleOrder(pageNum, pageSize);
}
/**
 * 主祥新增
 */
public Boolean saveSaleorder(Map<String,Object> map){
//	if(iSaleOrderMapper.querysaleOrderall(order.getBillNo())!=null){
//		iSaleOrderMapper.deleteSaleorder(order.getBillNo());
//	}
	try {
		iSaleOrderMapper.saveSaleorder(map);
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
	 return true;
}
/**
 * 查询最大的单号
 */
public String orderDanhao(Map<String,Object> map){
	String danhao=iSaleOrderMapper.orderDanhao(map);
//	String houdanhao=danhao.substring(0, 8);
//	Date d=new Date();
//	SimpleDateFormat date1=new SimpleDateFormat("yyyy-MM-dd");
//	String date2=date1.format(d);
//	String a=date2.replaceAll("-", "");
//	//存在+1
//	if(a==houdanhao){
//		Long l=Long.parseLong(danhao)+1;
//		danhao=l.toString();
//	}else{
//		//不存在默认第一单
//		danhao=a+"01";
//	}
	return TestUtil.getNewNo(danhao);
}
/**
 * 删除
 */
public void deleteSaleorder(String saleid){
	iSaleOrderMapper.deleteSaleorder(saleid);
}
/**
 * 根据订单编号查询主祥
 */
public SaleOrder querysaleOrderall(String saleid){
	return iSaleOrderMapper.querysaleOrderall(saleid);
}
/**
 * pageBean分页查询
 * @param map
 * @return
 */
public PageBean queryByPage(Integer currPage,Integer pageSize){
	int count=this.iSaleOrderMapper.queryCount();
	System.out.println(count);
	List<SaleOrder> saleorder=this.iSaleOrderMapper.queryPagesaleOrder((currPage-1)*pageSize, pageSize);
	PageBean pb=new PageBean(pageSize,count, currPage, saleorder);
	return pb;
}
/**
 * 根据主表编号查询项表记录
 */
public List<SaleOrderDetail> querySaleOrderDetailall(String saleid){
	return iSaleOrderMapper.querySaleOrderDetailall(saleid);
}
/**
 * 反审核审核
 */
public void updatedate(Integer auditState, String auditTime,String permitter,String billNo){
	iSaleOrderMapper.updatedate(auditState, auditTime, permitter, billNo);
}
}
